<?php

namespace app\shop\model;

use app\BaseModel;
use think\facade\Cache;
use think\Db;



//*------------------------------------------------------ */
//-- 订单表
/*------------------------------------------------------ */

class PrizeWinModel extends BaseModel
{
    protected $table = 'shop_prize_win';
    public $pk = 'id';
    protected $mkey = 'shop_goods_mkey_';
    public $config = [];

    public function initialize()
    {
        parent::initialize();
        $this->config = config('config.');
    }
    /*------------------------------------------------------ */
    //-- 清除缓存
    /*------------------------------------------------------ */
    public function cleanMemcache($order_id = 0)
    {
        Cache::rm($this->mkey . $order_id);
        Cache::rm($this->mkey . '_goods_' . $order_id);
        if ($this->userInfo['user_id'] > 0) {
            Cache::rm($this->mkey . '_user_stat_' . $this->userInfo['user_id']);
        }
    }

    /*------------------------------------------------------ */
    //-- 写入订单日志
    /*------------------------------------------------------ */
    function _log(&$order, $logInfo = '')
    {
        return OrderLogModel::_log($order, $logInfo);
    }

    /*
     * 查询奖品名称
     */
    public function getNameBygoodid($id){
        if(empty($id)){
            return '';
        }
        $res = Db::table('shop_prize_goods')->where('id',$id)->find();
        if($res){
            return $res['name'];
        }else{
            return '';
        }

    }

    /*
     * 查询奖品价格
     */
    public function getPriceByuid($id){
        if(empty($id)){
            return '';
        }
        $res = Db::table('shop_prize_goods')->where('id',$id)->find();
        if($res){
            return $res['price'];
        }else{
            return '';
        }

    }

    /*
     * 查询奖品图片
     */
    public function getphotoprizeByuid($id){
        if(empty($id)){
            return '/static/public/images/errorImage.jpg';
        }
        $res = Db::table('shop_prize_goods')->where('id',$id)->find();
        if($res){
            if(empty($res['photo'])){
                return '/static/public/images/errorImage.jpg';
            }else{
                return $res['photo'];
            }

        }else{
            return '/static/public/images/errorImage.jpg';
        }

    }



}
